﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HCQ2_Model.Pay
{
    /// <summary>
    /// 获取订单详细参数
    /// </summary>
    public class GetOrderDetailedParams : PayUser,IParentOrderID, IOrderState, IValidatableObject
    {
        /// <summary>
        /// 父订单号，为空时FileCode和OrderState必填，不为空时忽略FileCode和OrderState
        /// </summary>
        /// <remarks>       
        /// 20200910：改为非必填，ParentOrderCode有值时，忽略下面两个字段。文档《VLions需求规格-设备-20200910.docx》
        /// </remarks>
        //[Required(ErrorMessage ="父订单号不能为空")]
        public string ParentOrderCode { get; set; }

        /// <summary>
        /// 代码
        /// </summary>
        /// <remarks>
        /// 20200910：新增参数。文档《VLions需求规格-设备-20200910.docx》
        /// </remarks>
        public string FileCode { get; set; }

        /// <summary>
        /// 订单状态;1(等待买家付款)、(2买家已付款)、4(交易成功)、5(交易关闭)、6(退款中)
        /// </summary>
        /// <remarks>
        /// 20200910：新增参数。文档《VLions需求规格-设备-20200910.docx》
        /// </remarks>
        public int? OrderState { get; set; }

        /// <summary>
        /// 自定义验证
        /// </summary>
        /// <param name="validationContext"></param>
        /// <returns></returns>
        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            GetOrderDetailedParams getOrderDetailed = validationContext.ObjectInstance as GetOrderDetailedParams;
            if (getOrderDetailed != null)
            {
                //父单号为空，FileCode和OrderState必填
                if (string.IsNullOrEmpty(getOrderDetailed.ParentOrderCode) && (string.IsNullOrEmpty(getOrderDetailed.FileCode) || getOrderDetailed.OrderState == null))
                {
                    yield return new ValidationResult("父订单号为空，FileCode和OrderState必填", new string[] { "OrderState" });
                }
            }
        }
    }
}
